package com.wenhao.sf;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @create 2021-08-30 19:22
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] boss = new int[5];
        for (int i = 0;i < 5;i++) {
            boss[i] = scanner.nextInt();
        }
        int T = scanner.nextInt();
        int max = 0;
        List<Integer> list = null;
        for (int i = 0;i < T;i++) {
            int temp = 0;
            for (int j = 0;j < 5;j++) {
                temp += boss[j] * scanner.nextInt();
            }
            if (temp > max) {
                list = new ArrayList<>();
                list.add(i + 1);
                max = temp;
            } else if (temp == max) {
                list.add(i + 1);
            }
        }
        System.out.println(max);
        System.out.println(list.size());
        list.stream().forEach(System.out::println);
    }
}
